package com.heima.user.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

/**
 * @author: itheima
 * @create: 2022-08-07 11:32
 */
@Component
public class ShardingJob {

    /**
     * 分片任务：次任务调度将会广播触发对应集群中所有执行器执行一次任务
     * @return
     */
    @XxlJob("shardingJob") //要和xxl-job页面任务管理的新增的JobHandler一致
    public ReturnT<String> shardingJob(){
        System.out.println("任务执行了。。");
        int shardTotal = XxlJobHelper.getShardTotal();
        int shardIndex = XxlJobHelper.getShardIndex();
        System.out.println("总分片数量："+shardTotal);
        System.out.println("当前分片索引："+shardIndex);
        return ReturnT.SUCCESS;
    }
}
